<template>
  <div class="miniPage">
    <div class="topBgc" :style="{ backgroundImage: handleImage() }"></div>
    <div
      class="centerBox"
      :class="miniCouponInfo?.marCouponCount || couponInfo?.couponName ? 'boxFloorBgI' : ''"
    >
      <div class="boxBody" :style="{ textAlign: textAlignVal }">
        <div
          class="boxItem"
          :class="handleClass(item)"
          v-for="item in couponList"
          :key="item.id"
          @click.stop="handleClick(item)"
        >
          <div class="boxPrice">
            ￥
            <span class="price">{{ item?.money }}</span>
          </div>
          <div class="presented">赠{{ item?.giftGold }}元</div>
          <div class="_first" v-show="first?.credits">首充加赠{{ first?.credits }}元</div>
          <div
            v-show="item?.activityTag || first?.credits || couponInfo"
            :style="{
              backgroundImage: handleTopIcon(item?.activityTag)
            }"
            class="topIcon"
          >
            {{ item?.activityTag || '首充' }}
          </div>
        </div>
      </div>
      <div v-show="miniCouponInfo?.marCouponCount || couponInfo?.couponName" class="boxFloor">
        <div v-show="miniCouponInfo?.marCouponCount">
          赠{{ miniCouponInfo?.couponName }}{{ miniCouponInfo?.marCouponCount }}张
        </div>
        <div v-show="couponInfo"
          >首充赠{{ couponInfo?.couponName }}{{ couponInfo?.marCouponCount }}张</div
        >
        <div
          class="topLeftBox"
          v-show="miniCouponInfo?.extraStoredTag || first?.credits || couponInfo"
          >{{ miniCouponInfo?.extraStoredTag || '首次储值特惠' }}</div
        >
      </div>
    </div>
  </div>
</template>
<script setup>
import topBgc from '@/assets/images/top-bgc.png'
import firstIcon from '@/assets/images/first-icon.png'
import activitiesIcon from '@/assets/images/activities-icon.png'

import { deepClone } from '@/utils'

const props = defineProps({
  formParams: {
    type: Object
  }
})
const first = computed(() => props.formParams?.first)
const couponList = ref([])
const couponInfo = computed(() => props.formParams?.first?.couponInfo)
const miniCouponInfo = ref(null)
const textAlignVal = ref('left')
/**操作数组数据 */
function handleClick(item) {
  miniCouponInfo.value = item
  couponList.value?.forEach((i) => {
    i.isClick = i.id === item.id
  })
}
function handleTopIcon(activityTag) {
  return activityTag
    ? `url(${activitiesIcon})`
    : first.value?.credits || couponInfo.value
      ? `url(${firstIcon})`
      : 'url()'
}
function handleClass(item) {
  if (item.isClick) {
    return 'isClick'
  } else if (first.value?.credits) {
    return 'not-Click'
  }
}

function handleImage() {
  // console.log('activityImg', props.formParams.activityImg)
  const activityImg = props.formParams?.activityImg
  if (Array.isArray(activityImg) && activityImg.length > 0) {
    return `url(${activityImg[0]?.url})`
  } else if (activityImg) {
    return `url(${activityImg})`
  }
}
watch(
  () => props.formParams,
  (newVal) => {
    miniCouponInfo.value = newVal?.svadList[0] || null
    if (!newVal?.svadList?.length) return (couponList.value = [])
    couponList.value = deepClone(newVal.svadList)
    couponList.value?.forEach((i, index) => {
      i.isClick = index === 0
    })
    textAlignVal.value = couponList.value?.length === 3 ? 'center' : 'left'
    // console.log('couponList', couponList.value)
  },
  { deep: true }
)
//
</script>
<style lang="scss" scoped>
.miniPage {
  width: 375px;
  height: 813px;
  position: relative;
  .topBgc {
    position: absolute;
    left: 0px;
    top: 0px;
    width: 375px;
    height: 258px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    z-index: 1;
  }
  .centerBox {
    position: absolute;
    left: 0px;
    top: 0px;
    width: 375px;
    height: 813px;
    z-index: 2;
    background: url('@/assets/images/boxFloorBgI.png') no-repeat center;
    background-size: 100% 100%;
    .boxBody {
      width: 375px;
      min-height: 152px;
      overflow-x: auto;
      white-space: nowrap;
      margin-top: 242px;
      // text-align: center;
      .boxItem {
        margin-right: 10px;
        display: inline-block;
        font-size: 14px;
        width: 104px;
        height: 152px;
        border-radius: 16px;
        background: url('@/assets/images/not-selected.png') no-repeat center;
        background-size: 100% 100%;
        position: relative;
        .boxPrice {
          position: absolute;
          top: 40px;
          left: 0px;
          width: 100%;
          height: 40px;
          line-height: 40px;
          text-align: center;
          color: #79391d;
          font-size: 16px;
          font-family: DIN;
          font-weight: 700;
          .price {
            font-size: 30px;
          }
        }
        .presented {
          position: absolute;
          top: 81px;
          left: 0px;
          width: 100%;
          color: #79391d;
          text-align: center;
          font-family: 'PingFang SC';
          font-size: 14px;
          font-weight: 400;
          opacity: 0.6;
        }
        ._first {
          position: absolute;
          top: 101px;
          left: 0px;
          width: 100%;
          color: #79391d;
          text-align: center;
          font-family: 'PingFang SC';
          font-size: 12px;
          font-weight: 400;
          opacity: 0.6;
        }
        &:last-child {
          margin-right: 0px;
        }
        .topIcon {
          position: absolute;
          top: 0px;
          left: 50%;
          transform: translateX(-50%);
          background-size: 100% 100%;
          background-repeat: no-repeat;
          width: 54px;
          height: 23px;
          font-size: 12px;
          line-height: 23px;
          text-align: center;
          color: #fff;
        }
      }
      .not-Click {
        background: url('@/assets/images/not-selected.png') no-repeat center;
        background-size: 100% 100%;
      }
      .isClick {
        z-index: 2;
        background: url('@/assets/images/selected.png') no-repeat center;
        background-size: 100% 100%;
        // box-shadow: 0px 7px 7px 2px #edffe0;
        .boxPrice {
          color: #488b16;
        }
        .presented,
        ._first {
          color: #488b16;
          opacity: 0.6;
        }
      }
    }
    .boxFloor {
      margin-top: 55px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      padding: 0 0 0 12px;
      width: 176px;
      height: 74px;
      border-radius: 16px;
      background: url('@/assets/images/not-first.png') no-repeat center;
      background-size: 100% 100%;
      color: #666;
      font-family: 'PingFang SC';
      font-size: 12px;
      font-weight: 400;
      position: relative;
      .topLeftBox {
        position: absolute;
        top: 2px;
        left: 1.8px;
        color: #333;
        font-family: 'PingFang SC';
        font-size: 10px;
        padding: 2px 6px;
        border-radius: 14px 0px 12px 0px;
        background: #ffbe45;
      }
    }
    .firstBoxFloor {
      background: url('@/assets/images/first.png') no-repeat center;
      background-size: 100% 100%;
    }
  }
  .boxFloorBgI {
    background: url('@/assets/images/storedBgc.png') no-repeat center;
    background-size: 100% 100%;
    z-index: 2;
  }
}
</style>
